#include "mysessioncb.h"
#include <QDebug>

MySessionCB::MySessionCB(QObject *parent) : QObject(parent)
{

}

// 通过 SessionCallback 继承
void MySessionCB::createdCommunicator(const Glacier2::SessionHelperPtr & )
{
    stateChanged(STT_CREATEDCOMMUNICATOR);
}

void MySessionCB::connected(const Glacier2::SessionHelperPtr & )
{
    stateChanged(STT_CONNECTED);
}

void MySessionCB::disconnected(const Glacier2::SessionHelperPtr & )
{
    stateChanged(STT_DISCONNECTED);
}

void MySessionCB::connectFailed(const Glacier2::SessionHelperPtr & , const Ice::Exception & ex)
{
    stateChanged(STT_CONNECTFAILED, QString(ex.what()));
}

void MySessionCB::stateChanged(State s, const QString &reson)
{
    QString str;
    switch (s) {
    case STT_CREATEDCOMMUNICATOR:
        str = "createdCommunicator";
        break;
    case STT_CONNECTED:
        str = "connected";
        break;
    case STT_DISCONNECTED:
        str = "disconnected";
        break;
    case STT_CONNECTFAILED:
        str = "connectFailed reson:" + reson;
        break;
    default:
        break;
    }
    emit sig_Notify(s,str);
}
